<?php
class Level extends MY_Controller
{
	public function __construct()
	{
		log_message('debug', '=====开始调用Report->Level->__construct接口=====');
		parent::__construct();
		$this->loadLanguageFile('application/controllers/Report/');
		log_message('debug', '=====调用Report->Level->__construct接口结束=====');
	}
	
	public function showView() {
		$this->load->view('module/Report/level.htm');
	}
	
	public function getListData() {
		log_message('debug', '=====开始调用Report->Level->getListData接口=====');
		$this->verifyPrivilege();
		
		try {
			$gameAreaId = $this->param->getParam('gameAreaId', array('method' => 'int', 'min' => 1, 'emptyErrorCode' => 201, 'invalidErrorCode' => 1));
			$date = $this->param->getParam('date', array('method' => 'string', 'emptyErrorCode' => '2040001', 'invalidErrorCode' => 1));
			$page = $this->param->getParam('page', array('method' => 'int', 'min' => 1, 'emptyErrorCode' => 1, 'invalidErrorCode' => 1), 'post', true);
			$rows = $this->param->getParam('rows', array('method' => 'int', 'min' => 1, 'emptyErrorCode' => 1, 'invalidErrorCode' => 1), 'post', true);
			$this->initGameAreaInfo($gameAreaId);
			
			$sql = "
				select
					<selectColumns>
				from
					`t_data_level_report`
				where
					`gameAreaId` = '{$gameAreaId}'
					and
					`date` = '{$date}'
			";
			$getTotalSql = str_replace('<selectColumns>', "count(*)", $sql);
			//error_log("getTotalSql = ".$getTotalSql);
			$this->returnData['data']['total'] = $this->gmDatabase->getColumn($getTotalSql);
			$getDataSql = str_replace('<selectColumns>', "`level`, `roleNum`, `payRoleNum`", $sql);
			$getDataSql = $getDataSql.' order by level';
// 			if($page && $rows) {
// 				$startRow = ($page - 1) * $rows;
// 				$getDataSql .= " limit {$startRow}, {$rows}";
// 			}
			//error_log("getDataSql sql = ".$getDataSql);
			$this->returnData['data']['rows'] = $this->gmDatabase->getArray($getDataSql);
		}
		
		catch(MY_Param_Exception $e) {
			$this->setErrorCode($e->getCode());
		}
		
		catch(MY_Mysql_Exception $e) {
			$this->setErrorCode(1);
		}
		
		catch(Exception $e) {
			$this->setErrorCode($e->getCode());
		}
		
		$this->returnJson();
		log_message('debug', '=====调用Report->Level->getListData接口结束=====');
	}
}